<?php

require_once 'include/config.php';
require_once 'include/http.php';
require_once 'wechat.php';
$upload = new user();
class user{
    
    
    private $appid = '';
    private $appsecret = '';
    private $http = '';
    
    public function __construct() {
        $this->appid = constant('APPID');
        $this->appsecret = constant('APPSECRET');
        $this->http = new http();
        //获取access_token
        $wechat = new wechat();
        $this->access_token = $wechat->getAccessToken();
    }
    
    //发送客服消息
    public function getUserList($next_openid = "") {
        //读取数据库
        $list = '';
        //如果没有就去这边获取
        if(empty($list)){
            $url = "https://api.weixin.qq.com/cgi-bin/user/get?access_token={$this->access_token}&next_openid={$next_openid}";
            $user = $this->http->http_request($url);
            $openList = json_decode($user,true);
            $openList = $openList['data']['openid'];
            foreach ($openList as $key => $value) {
                $list[$key] = $this->getUserInfo($value);
                //查询是否有
                $info = '';
                //如果没有就插入数据库
                if(empty($info)){
                    
                }
            }
        }
        return $list;
    }
    //获取用户基本信息
    public function getUserInfo($openid) {
        $url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token={$this->access_token}&openid={$openid}&lang=zh_CN";
        $user = $this->http->http_request($url);
        $json = json_decode($user,true);
        return $json;
    }
    
}

